#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :model.py
# @Time      :2025/2/14 16:45
# @Author    :kk
from mongoengine import Document, StringField, DateTimeField

from exts import db, mongo
from datetime import datetime

##############mysql####################################################
class UserModel(db.Model):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), nullable=False, unique=True)
    join_time = db.Column(db.DateTime, default=datetime.now)

class EmailCaptchaModel(db.Model):
    __tablename__ = "email_captcha"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(100), nullable=False)
    captcha = db.Column(db.String(50), nullable=False)
    used = db.Column(db.Boolean, default=False)

############mongodb#####################################################
class Article(Document):
    meta = {'collection': 'articles'}
    title = mongo.StringField(required=True, max_length=200)
    author = mongo.StringField(required=True, max_length=100)
    published_date = mongo.DateTimeField(default=datetime.now)
    content = mongo.StringField(required=True, max_length=2000)